package com.hua.common;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.hua.entities.Employee;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;


@Component
@Slf4j
public class MyMataObjectHandle implements MetaObjectHandler {

    //插入时填充
    @Override
    public void insertFill(MetaObject metaObject) {
//        employee.setCreateTime(LocalDateTime.now());
//        employee.setUpdateTime(LocalDateTime.now());
//        Employee user = (Employee) request.getSession().getAttribute("user");
//        employee.setUpdateUser(user.getId());
//        employee.setCreateUser(user.getId());
        log.info("插入时填充~~~~");
        metaObject.setValue("createTime",LocalDateTime.now());
        metaObject.setValue("updateTime",LocalDateTime.now());
        metaObject.setValue("createUser",BaseTool.getInfo());
        metaObject.setValue("updateUser",BaseTool.getInfo());
    }
    //更新时候填充
    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("更新时填充~~~~");
        metaObject.setValue("updateTime",LocalDateTime.now());
        metaObject.setValue("updateUser",BaseTool.getInfo());
    }
}
